
const Controller = require('egg').Controller;

class HomeController extends Controller {
  async getList() {
    const { ctx } = this;
    const data = await ctx.service.list.getList()
    ctx.body= data
  }
  async addList(){
    const {ctx}=this;
    const data = await ctx.service.list.addList()
    if(data.affectedRows===1){
      ctx.body={
        message:"添加成功",
        data:{
          id:data.insertId
        },
        code:1
      }
    }else{
      ctx.body={
        message:"添加失败",
        code:-1
      }
    }
  }
 
  async editList(){
    const {ctx}=this;
    const data = await ctx.service.list.editList()
    if(data.affectedRows===1){
      ctx.body={
        message:"编辑成功",
        code:1
      }
    }else{
      ctx.body={
        message:"编辑失败",
        code:-1
      }
    }
  }
  // async delete(){
  //   const {ctx}=this
  //   const data = await ctx.service.list.delete()
  //   if(data.affectedRows===1){
  //     ctx.body={
  //       message:"删除成功",
  //       code:1
  //     }
  //   }else{
  //     ctx.body={
  //       message:"删除失败",
  //       code:-1
  //     }
  //   }
  // }
  async delete() {
    const { ctx } = this;
    let res = await ctx.service.list.delete()
    ctx.body =res;
  }
}

module.exports = HomeController;
